package com.platform.controller.backend;

import com.platform.common.ServerResponse;
import com.platform.pojo.RoleMenu;
import com.platform.service.IRoleMenuService;
import com.platform.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 角色菜单控制层
 */
@Controller
@RequestMapping("/roleMenuController/")
public class RoleMenuController {

    @Autowired
    private IRoleMenuService iRoleMenuService;

    @RequestMapping(value = "add.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<String> insert(RoleMenu roleMenu){
        return iRoleMenuService.insert(roleMenu);
    }

    @RequestMapping(value = "del.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<String> del(Integer id){
        return iRoleMenuService.del(id);
    }

    @RequestMapping(value = "selectByRoleCode.do",method = RequestMethod.GET)
    @ResponseBody
    public ServerResponse<List<Integer>> selectByRoleCode(String roleCode){
        return iRoleMenuService.selectByRoleCode(roleCode);
    }

    /**
     * 保存角色菜单权限
     * @return
     */
    @RequestMapping(value = "addRoleMenu.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<String> addRoleMenu(@RequestParam Map param, HttpServletRequest request){

        return iRoleMenuService.addRoleMenu(StringUtil.valueOfString(param.get("roleCode")),
                StringUtil.valueOfString(param.get("menuIdArr")));
    }
}
